package com.didiglobal.booster.gradle

import com.android.builder.model.Version
import com.android.repository.Revision
import com.didiglobal.booster.android.gradle.v3_0.V30
import com.didiglobal.booster.android.gradle.v3_2.V32
import com.didiglobal.booster.android.gradle.v3_3.V33
import com.didiglobal.booster.android.gradle.v3_4.V34
import com.didiglobal.booster.android.gradle.v3_5.V35
import com.didiglobal.booster.android.gradle.v3_6.V36
import com.didiglobal.booster.android.gradle.v4_0.V40
import com.didiglobal.booster.android.gradle.v4_1.V41
import com.didiglobal.booster.android.gradle.v4_2.V42

internal val ANDROID_GRADLE_PLUGIN_VERSION: Revision = Revision.parseRevision(Version.ANDROID_GRADLE_PLUGIN_VERSION)
internal val MAJOR = ANDROID_GRADLE_PLUGIN_VERSION.major
internal val MINOR = ANDROID_GRADLE_PLUGIN_VERSION.minor

val GTE_V3_X = MAJOR >= 3
val GTE_V3_6 = MAJOR > 3 || (MAJOR == 3 && MINOR >= 6)
val GTE_V3_5 = MAJOR > 3 || (MAJOR == 3 && MINOR >= 5)
val GTE_V3_4 = MAJOR > 3 || (MAJOR == 3 && MINOR >= 4)
val GTE_V3_3 = MAJOR > 3 || (MAJOR == 3 && MINOR >= 3)
val GTE_V3_2 = MAJOR > 3 || (MAJOR == 3 && MINOR >= 2)
val GTE_V3_1 = MAJOR > 3 || (MAJOR == 3 && MINOR >= 1)

val GTE_V4_X = MAJOR >= 4
val GTE_V4_2 = MAJOR > 4 || (MAJOR == 4 && MINOR >= 2)
val GTE_V4_1 = MAJOR > 4 || (MAJOR == 4 && MINOR >= 1)

internal val AGP: AGPInterface = arrayOf(
        GTE_V4_2 to V42,
        GTE_V4_1 to V41,
        GTE_V4_X to V40,
        GTE_V3_6 to V36,
        GTE_V3_5 to V35,
        GTE_V3_4 to V34,
        GTE_V3_3 to V33,
        GTE_V3_2 to V32,
        GTE_V3_X to V30
).firstOrNull(Pair<Boolean, AGPInterface>::first)?.second ?: throw TODO("Incompatible with AGP $ANDROID_GRADLE_PLUGIN_VERSION")
